package com.wandian.centerserver;

import com.wandian.texas.GameData;
import com.wandian.texas.IoHandlerAdapter;
import com.wandian.texas.SessionObject;
import com.wandian.texas.UserMgr;
import com.wandian.texas.db.DBMgr;
import com.wandian.texas.db.DaoManager;
import com.wandian.util.Log;

/**
 * @author long
 * @date 2012-12-7 下午3:14:28
 * @qq 108232706
 * @description CenterIoHandler
 */
public class CenterIoHandler extends IoHandlerAdapter {
	@Override
	public void sessionCreated(SessionObject session) throws Exception {
		Log.info(String.format("[CenterIoHandler]有玩家上线,ip %s,当前在线人数%s", session.ipAddress, GameData.ONLINECOUNT.get()));
	}

	@Override
	public void sessionClosed(SessionObject session) throws Exception {
		Log.info(String.format("[CenterIoHandler]有玩家断线,ip %s,当前在线人数%s", session.ipAddress, GameData.ONLINECOUNT.get()));
		// 用户组删除
		if (session.getAttribute("serverid") != null) {
			int serverid = Integer.parseInt(session.getAttribute("serverid").toString());
			UserMgr.I().loginOff(serverid, session);
			if (DaoManager.GameRoomDao(0).executeProcedureReturn("sp_ServerLogoff", DBMgr.TexasPokerDB, serverid) != 1) {

			}
		}
	}

	@Override
	public void exceptionCaught(SessionObject session, Throwable cause) throws Exception {

	}
}
